<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
    <div id="send"> 
        <input type="text"
            value="">
        <input type="text" value="">
        <input type="text" value="">
        <input type="text" value="">
        <input type="button" value="发送">
    </div>
    <script>
         //删除按钮
        function deleteProduct() {
            let deleteBtns = document.querySelectorAll('.delete-btn');
            for (let i = 0; i < deleteBtns.length; i++) {
                deleteBtns[i].onclick = function () {
                    //调用删除接口
                    let uid = localStorage.getItem('uid')
                    let token = localStorage.getItem('token')
                    // pid  按钮上 属性里面
                    let pid = this.getAttribute('data-id')
                    let url = 'http://jx.xuzhixiang.top/ap/api/goods/goods-delete.php'
                    axios.get(url, {
                        params: {
                            uid, token, pid
                        }
                    }).then(res => {
                        console.log(res.data);
                        this.parentNode.remove()
                    })
                }
            }
        }

        //发布商品
        function publishProduct() {
            let ipts = document.querySelectorAll('#send input')
            ipts[4].onclick = function () {
                let pimg = ipts[0].value
                let pname = ipts[1].value
                let pdesc = ipts[2].value
                let pprice = ipts[3].value
                let uid = localStorage.getItem('uid')

                let pAPI = 'http://jx.xuzhixiang.top/ap/api/goods/goods-add.php'
                axios.get(pAPI, { params: { pimg,pname,pdesc, pprice, uid } })
                    .then(res => {
                        console.log(res.data);
                    })


            }
        }


        deleteProduct()
        publishProduct()
    </script>
</body>
</html>